package com.niit.springbootshop.tools;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class MD5Util {

	public static String encode(String value) {
		String result=null;
		try {
			// 确定加密方式 是 MD5
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			// 编码器
			BASE64Encoder encoder = new BASE64Encoder();
			byte[] data = value.getBytes("utf-8");
			data[2]=97;
			data[0]=98;
			// 加密字符串
			result = encoder.encode(md5.digest(data));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return result;
	}
	public static void main(String[] args) {
		System.out.println(encode("123456"));
		System.out.println(encode("123456"));
	}
}
